package entity.SCM;

import entity.FRM.SupplierInvoice;
import entity.FRM.SupplierPayment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Supplier implements Serializable {
    @Id
    private String supplierName;
    private String supplierAddress;
    private String supplierPostcode;
    private String supplierContactNo;
    private String supplierEmail;
    private State supplierState;
    @OneToMany
    private List<SupplyItem> supplyItemList = new ArrayList<SupplyItem>();
    
    public enum State{exist, delete};
    @OneToMany
    private List<MaterialOrder> materialOrderList = new ArrayList<MaterialOrder>();
    @OneToMany
    private List<SupplierInvoice> supplierInvoices = new ArrayList<SupplierInvoice>();
    @OneToMany 
    private List<SupplierPayment> supplierPayments = new ArrayList<SupplierPayment>();
    
    public List<MaterialOrder> getMaterialOrderList() {
        return materialOrderList;
    }

    public void setMaterialOrderList(List<MaterialOrder> materialOrderList) {
        this.materialOrderList = materialOrderList;
    }

    public String getSupplierContactNo() {
        return supplierContactNo;
    }

    public void setSupplierContactNo(String supplierContactNo) {
        this.supplierContactNo = supplierContactNo;
    }

    public State getSupplierState() {
        return supplierState;
    }

    public void setSupplierState(State supplierState) {
        this.supplierState = supplierState;
    }
    
    public String getSupplierPostcode() {
        return supplierPostcode;
    }

    public void setSupplierPostcode(String supplierPostcode) {
        this.supplierPostcode = supplierPostcode;
    }

    public String getSupplierAddress() {
        return supplierAddress;
    }

    public void setSupplierAddress(String supplierAddress) {
        this.supplierAddress = supplierAddress;
    }

    public String getSupplierEmail() {
        return supplierEmail;
    }

    public void setSupplierEmail(String supplierEmail) {
        this.supplierEmail = supplierEmail;
    }
    
    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public List<SupplyItem> getSupplyItemList() {
        return supplyItemList;
    }

    public void setSupplyItemList(List<SupplyItem> supplyItemList) {
        this.supplyItemList = supplyItemList;
    }
    
    public List<MaterialOrder> getCompletedMaterialOrders()
    {
        List<MaterialOrder> temp = new ArrayList<MaterialOrder>();
        for (MaterialOrder temp_materialOrder:this.getMaterialOrderList())
        {
            if (temp_materialOrder.getMaterialOrderState()==MaterialOrder.State.Received)
            temp.add(temp_materialOrder);
        }
        
        if (temp.size()!=0)
            System.out.println("getCompletedMaterialOrders"+temp.get(0).getMaterialOrderId().toString());
        return temp;
    }

    public List<SupplierInvoice> getSupplierInvoices() {
        return supplierInvoices;
    }

    public void setSupplierInvoices(List<SupplierInvoice> supplierInvoices) {
        this.supplierInvoices = supplierInvoices;
    }

    public List<SupplierPayment> getSupplierPayments() {
        return supplierPayments;
    }

    public void setSupplierPayments(List<SupplierPayment> supplierPayments) {
        this.supplierPayments = supplierPayments;
    }        
    
    public List<SupplierInvoice> getSupplierInvoices_Pending()
    {
        List<SupplierInvoice> temp = new ArrayList<SupplierInvoice>();
        for (SupplierInvoice temp_SupplierInvoice: this.getSupplierInvoices())
            if (temp_SupplierInvoice.getStateSupplierInvoice()==SupplierInvoice.StateSupplierInvoice.Pending)
                temp.add(temp_SupplierInvoice);
        
        return temp;
    }
}
